package rpc.netty.http;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import rpc.core.FlowReq;
import rpc.core.FlowRes;
import rpc.core.plugin.impl.proxy.ServiceProxy;

public class WebRouteInfo {

  private ServiceProxy serviceProxy;
  private String path;


  public WebRouteInfo setServiceProxy(ServiceProxy serviceProxy) {
    this.serviceProxy = serviceProxy;
    return this;
  }

  public String getPath() {
    return path;
  }

  public WebRouteInfo setPath(String path) {
    this.path = path;
    return this;
  }


  public CompletableFuture<FlowRes> invoke(Map<String, Object> paramsMap) {

    return invoke(new FlowReq(paramsMap));
  }

  public CompletableFuture<FlowRes> invoke(FlowReq req) {
    return serviceProxy != null ? this.serviceProxy.invoke(req) : CompletableFuture.completedFuture(new FlowRes().fail(-812));
  }

}
